#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+7;
ll d[N],v[N],a[N],p[N];
bool mrk[N];
struct node{
    ll l,r;
}op[N];
bool cmp(node xx,node yy){
    if(xx.r==yy.r) return xx.l<yy.l;
    return xx.r<yy.r;
}
int main(){
     freopen("detect.in","r",stdin);
     freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T; cin>>T;
    while(T--){
        memset(mrk,0,sizeof(mrk));
        memset(op,0,sizeof(op));
        ll n,m,L,V;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];//p->m
        }
        int cnt=0;
        bool ok=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&d[i]<=p[m]) {mrk[i]=1;cnt++;}
            }
            else if(a[i]>0){
                ll x=p[m]-d[i];
                if(v[i]*v[i]+2*a[i]*x>V*V&&d[i]<=p[m]){mrk[i]=1;cnt++;}
            }
            else{
                ok=1;
                ll wz=lower_bound(p+1,p+1+m,d[i])-p;
                ll x=p[wz]-d[i];
                if(v[i]*v[i]+2*a[i]*x>V*V&&d[i]<=p[m]) {mrk[i]=1;cnt++;}
            }
        }
        if(cnt==0) {cout<<cnt<<" "<<m<<'\n';continue;}

        if(ok==0) {cout<<cnt<<' '<<m-1<<'\n';continue;}
        cout<<cnt<<" ";
        int tot=0;
        
        for(int i=1;i<=n;i++){
            if(a[i]<0&&mrk[i]==1){
                ll wz=lower_bound(p+1,p+1+m,d[i])-p;
                op[++tot].l=wz;
                ll ql=wz,qr=m;
                while(ql<qr){
                    ll mid=(ql+qr+1)>>1;
                    ll x=p[mid]-d[i];
                    if(v[i]*v[i]+2*a[i]*x>V*V) ql=mid;
                    else qr=mid-1;
                }
                op[tot].r=ql;
            }
        }
       
        sort(op+1,op+tot+1,cmp);
        // for(int i=1;i<=tot;i++){
        //     cout<<"*******"<<i<<" "<<op[i].l<<" "<<op[i].r<<'\n';
        // }
        ll ans=1;
        ll st=op[1].r;
        for(int i=1;i<=tot;i++){
            if(op[i].l>st) st=op[i].r,ans++;
        }
        bool fl=0;
        // cout<<"&&&"<<ans<<'\n';
        for(int i=1;i<=n;i++){
            if(a[i]>0&&mrk[i]==1){
                if(d[i]>p[st]) {fl=1;break;}
                ll x=p[st]-d[i];
                if(v[i]*v[i]+2*a[i]*x<=V*V) fl=1;
            }
            else if(a[i]==0&&mrk[i]==1){
                if(d[i]>p[st]) fl=1;
            }
        }
        if(fl==1) cout<<m-ans-1<<'\n';
        else cout<<m-ans<<'\n';
    }

    return 0;
}
/*

*/